function ProcessDataFiles
path1 = '/Volumes/300GB iceCUBE G2/DataEmotion/EmotionExp2';
%path2 = '/Volumes/My Book/EmotionExp';
path2 = '/Volumes/HD-LBU2/TwentyElevenData/';
if exist(path1)
  pathtofiles = path1;
elseif exist(path2)
  pathtofiles = path2;
end





% read in data
fidout = fopen('dataAdjusted2011.txt','w');
fprintf(fidout,'numID\tFilename\tLevel\tTimeToPutative\tTimeForMovement\tTimeOutOfBox\tTimeFirstFace\tLocus\tAccuracyProp\tAccuracyFirst\tLike\tKnow\tEmo\tPreceding\tExcerpt\tAge\tAge Group\tMus\tGender\tLanguage\tSID\tFavourite Face\tWorst Face\tFaceChosenProp\tFaceChosenFirst\tTargetFaceChosen\tValenceMean\tArousalMean\t Angry\tScared\tSad\tCalm\tHappy\tExcited\tCentre\tElsewhere\n');
% get all the Demographics Files
demog = rdir([pathtofiles '/**/*Demographics*.txt']);



% TS Filehandles
for fh = 1:19
    fHandles(fh) = fopen(strcat('excerpt',num2str(fh-1),'TS.txt'),'w');
    fprintf(fHandles(fh), 'Time\tFilename\tID\tSID\tExcerpts\tEmotion\tLike\tKnow\tLevel\tLocus\tAge\tGender\tMus\tPreceding\n'); 
end
   


% TS Filehandles
for fh = 1:6
    fHandlesTraining(fh) = fopen(strcat('training',num2str(fh),'TS.txt'),'w');
    fprintf(fHandlesTraining(fh), 'Time\tFilename\tID\tSID\tExcerpts\tEmotion\tLike\tKnow\tLevel\tLocus\tAge\tGender\tMus\tPreceding\n'); 
end

outResponseTime = [];
num = 1;
time = [];
%%%
% Start loop for first demographic file

wavfileProbs = 0;
for demFile = 1:length(demog)
  %Progress
  fprintf('*********** File %d of %d *********** \n',demFile,length(demog));
  
  
  % This skips all the 2010 data (including the young children (Student Data folder) 
  % and the 50 tertiary students (ZAdult Data folder). Comment these 3 lines out to 
  % include this data in the processing.
  
%   if findstr(demog(demFile).name,'Student')|findstr(demog(demFile).name,'ZAdult')
%     disp('Skipping 2010 data');
%     continue;
%   end
  
  
  
    
  
  % end of commenting (regarding above note).
  
  % read file
  disp(demog(demFile).name);
  fidDem=fopen(demog(demFile).name);
  while 1
    dt= fgetl(fidDem);
    if ~ischar(dt), break, end
    lastLine = dt;
  end
  fclose(fidDem);
  [path,fndemog] = fileparts(demog(demFile).name);
  if strcmp(fndemog(1),'.')
      continue
  end
  
  
  numID = strrep(fndemog,'-Demographics','');
  numIDPos = strfind(lastLine,numID);
  lastLine= lastLine(numIDPos(end):end);
  clear('SID');
  SIDpos = strfind(numID,'-');
  SID    = numID(SIDpos(end)+1:end);
  dems = textscan(lastLine,'%s%f%f%f%f%s%d%d%q%q%q%q');

  disp(SID);
  % Set variables for the demographics
  id = dems{1};
  age = dems{2} + dems{3}/12;
  mus = dems{4} + dems{5}/12;
  gender = dems{6};
  faveFace = dems{7};
  worstFace = dems{8};
  lang = [char(dems{9}) ' ' char(dems{10}) ' ' char(dems{11}) ' ' char(dems{12})];

  % get files for the excerpts
  fn = strrep(demog(demFile).name,'-Demographics','');
  fidExc = fopen(fn);
  if fidExc == -1
    warning(['couldn''t get at: ' fn]); 
    continue
  end
  
  
  for line = 1:27 % Ignore Level 3
    exc = textscan(fidExc,'%s%s%q%q%q%q%q%s%q%q\n');
    if line <3
        
      continue;
    end
    if isempty(exc{2}) 
      break; 
    end
    TimeRec(line) = exc{2};
    Know(line) = exc{3};
    KnowExtra(line) = exc{4};
    Like(line) = exc{5};
    LikeExtra(line) = exc{6};
    Level(line) = exc{7};
    Locus(line) = exc{8};
    excerpttmp(line)= exc{9};
    spacePos = cell2mat(strfind(exc{9},' '));
    spacePos(end+1) = length(exc{9}{1});
    
    Excerpts(line) = {exc{9}{1}(spacePos(1)+1:spacePos(2)-1)};
    Preceding(line) = {'None'};
  end
  fclose(fidExc);
  
  % What about level 2???
  for line = 24:26
    TimeRec(line+4) = TimeRec(line);
    Know(line+4) = Know(line);
    KnowExtra(line+4) = KnowExtra(line);
    Like(line+4) = Like(line);
    LikeExtra(line+4) = LikeExtra(line);
    Level(line+4) = Level(line);
    Locus(line+4) = Locus(line);
    spacePos = strfind( excerpttmp{line},' ');
    spacePos(end+1) = length(excerpttmp{line});
    Excerpts(line+4) = {excerpttmp{line}(spacePos(2)+1:spacePos(3)-1)};
    Preceding(line+4) = Excerpts(line);
  end
  
  level3exc = excerpttmp{27};
  % What about Level 3 ?
  for line = 1:6
    TimeRec(30+line) = TimeRec(27);
    Know(30+line) = Know(27);
    KnowExtra(30+line) = KnowExtra(27);
    Like(30+line) = Like(27);
    LikeExtra(30+line) = LikeExtra(27);
    Level(30+line) = Level(27);
    Locus(30+line) = Locus(27);
    spacePos = strfind(level3exc,' ');
    spacePos(end+1) = length(level3exc);
    
    Excerpts(30+line) = {level3exc(spacePos(line+1)+1:spacePos(line+2)-1)};
    if line == 1
      Preceding(30+line) = Excerpts(27);
    else
      Preceding(30+line) = Excerpts(30+line-1);
    end
  end
  
  resFiles = rdir([pathtofiles '/**/' id{1} '*' '.aiff']);
  numfiles = length(resFiles);
  if numfiles == 0
    resFiles = rdir([pathtofiles '/**/' id{1} '*' '.wav']);
    numFiles2 = length(resFiles);
    if numFiles2 > numfiles
      wavfileProbs = wavfileProbs +1;
    disp(['>>>>>>>>>>>> Aiff Files: ' num2str(numfiles) ' Wav Files: ' num2str(numFiles2) ' Probs: ' num2str(wavfileProbs) ' <<<<<<<<<<<<<<']);
    end
    continue;
  end
  
  
  % For Level 2
  resFiles(26:28) = resFiles(22:24);
  % For Level 3
  resFiles(29:34) = resFiles(25);
  
  totalLevel3 = 0;
  % Start loop for the first excerpt
  plotnum=1;
  for file = 1:length(resFiles)
    
    
    
    % Clear some stuff just in case
    data= [];
    time = [];
    dataTrue=[];
    dataAny = [];
    
    % Read the file details from the audio filename
    %file
    %resFiles(file).name
    [folders,filename,extension]=fileparts(resFiles(file).name);
    fn = textscan([filename extension],'%d%d%d%d%d%s%s%d%s','delimiter','-@');
    currentfile = file;
    
    
    
    % Skip the Instructions and Level 3 (for now)
    if currentfile  > 34 ||  currentfile  < 2
      continue;
    elseif  currentfile  >= 8 || currentfile  <= 24
      presFormat = 'Excerpt';
    elseif  currentfile  > 1 || currentfile  <= 7
      presFormat = 'Training';
    end
    
    
    % Get excerpt audio data
    [data,fs] = aiffread(resFiles(file).name);
    % Translate to 0-1
    data = data(:,3:4)/32768;
    
    % This is where we curtail the length of the section - for level 2
    % we curtail to a different portion so that the second excerpt can
    % be worked out.
    
    if strcmp(Preceding{currentfile+2}, 'None')
      [emo,len] = readExcerptData(Excerpts{currentfile+2}, pathtofiles);
      len = len + fs*5; % 5 seconds later.
      if len > fs*30, len = fs*30; end
      data = data(1:len,1:2);
      fprintf('Filename: %s\n Length %.1f',resFiles(file).name,len/fs);
    else
      [emoprec,lenprec] = readExcerptData(Preceding{currentfile+2},pathtofiles);
      if strcmp(Level{currentfile+2}, 'Level3')
        totalLevel3 = totalLevel3 + lenprec;
        [emo,len] = readExcerptData(Excerpts{currentfile+2},pathtofiles);
        len = len + totalLevel3 + fs*5; % 5 seconds after the end.
        lenprec = totalLevel3;
      else
        [emo,len] = readExcerptData(Excerpts{currentfile+2},pathtofiles);
        len = len + lenprec + fs*5; % 5 seconds later.
      end
      data =data(lenprec:len,1:2);
      fprintf('Preceding: %s Excerpt: %s\n Length1 %.1f Length2 %.1f',Preceding{currentfile+2}, Excerpts{currentfile+2},lenprec/fs,len/fs);
    end
    
    
    
    % This gets the proportion of time
    [prop,topface,targetemochosen] = assessEmotionData(data,emo);
    
    % Decide when the pointer is in the right location
    [emoPosX,emoPosY] = readEmotionPos(emo);
    
    dataTrue(:,1) = (data(:,1) > emoPosX(1)) & (data(:,1) < emoPosX(2));
    dataTrue(:,2) = (data(:,2) > emoPosY(1)) & (data(:,2) < emoPosY(2));
    dataTrue = (dataTrue(:,1) + dataTrue(:,2)) == 2;
    time = find(dataTrue == 1, 1,'first') / fs;
    
    if isempty(time); time = NaN; end
    dataAny(:,1) = (data(:,1) > 0.45) & (data(:,1) < 0.55);
    dataAny(:,2) = (data(:,2) > 0.45) & (data(:,2) < 0.55);
    dataAny  = (dataAny(:,1)  + dataAny(:,2)) ~= 2;
    % Find the first instance and calc time
    rtime = find(dataAny == 1, 1,'first') / fs;
    if isempty(rtime)
      rtime = NaN;
    end
    
    [emoPosX(1:2,1),emoPosY(1:2,1)] = readEmotionPos('Angry');
    [emoPosX(1:2,2),emoPosY(1:2,2)] = readEmotionPos('Scared');
    [emoPosX(1:2,3),emoPosY(1:2,3)] = readEmotionPos('Sad');
    [emoPosX(1:2,4),emoPosY(1:2,4)] = readEmotionPos('Calm');
    [emoPosX(1:2,5),emoPosY(1:2,5)] = readEmotionPos('Happy');
    [emoPosX(1:2,6),emoPosY(1:2,6)] = readEmotionPos('Excited');
    lastreal = find(flipud(data(:,1))~=0,1,'first');
    
    
    
    % test each emotion against the timeseries data
    for emoNum = 1:6
      dataTrueR = [];
      t = [];
      dataTrueR(:,1) = (data(:,1) > emoPosX(1,emoNum)) & (data(:,1) < emoPosX(2,emoNum));
      dataTrueR(:,2) = (data(:,2) > emoPosY(1,emoNum)) & (data(:,2) < emoPosY(2,emoNum));
      dataTrueR = (dataTrueR(:,1) + dataTrueR(:,2)) == 2;
      t = find(dataTrueR == 1, 1,'first');
      if isempty(t)
        timeAll(emoNum)= NaN;
      else
        timeAll(emoNum)= t / fs;
      end
    end
    % Time until any of the Faces
    [tAll,tAllIndex] = min(timeAll);
    

    
    % As an alternative to a threshold based around the box around each face
    % ( which is above as tALL), we use the time until a movement of 0.05
    % (normalised to screen res of 1.0)  is made. This is useful, as it is
    % a measure which can work OK for Level 2 and Level 3, when the
    % participant may start an excerpt with their pointer already on a
    % face, and we may want to know the time until the pointer begins to move above a given velocity a
    % certain distance away from the face. This does not, however, mean
    % that the participant has pointed at a particular face at all, only
    % that they have decided to move a certin distance. 
    %
    % This uses differencing and pythagoras to calculate a 5% movement.
    
    % In other words, this is a 'margin' of 'error' (somewhat like a jitter 
    % detection, but completely different).  So, if immediate movement was 
    % considered begining of the trajectory to the desired face, there
    % could be some dithering with no desired target.  The current method
    % 'waits' for an accumulated amount of movement timed FROM the very
    % begin of the current excerpt (e.g. the second exceprt in a level2
    % simulus.
    
    timeMove = readTimeUntilMovement(data,fs);
    
    % Work out which of the emotions is the most popular and use that
    % as the final choice. Ignore the centre and elsewhere conditions.
    [me,mei] = max(prop(1:6));
    emos = {'Angry','Scared','Sad','Calm','Happy','Excited'};
    actualemo = emos{mei};
    firstemo = emos{tAllIndex};
    
    % Update screen
    fprintf(' RT: %.2f, T: %.2f, TM: %.2f, PEmo: %s ActEmo: %s \n', time, rtime, timeMove, emo, actualemo);
    % Work out how right or wrong the choice was.
    Accuracy = abs(find(strcmp(actualemo,emos)) - find(strcmp(emo,emos)));
    AccuracyFirst = abs(find(strcmp(emos{tAllIndex},emos)) - find(strcmp(emo,emos)));
    
    % Means for the data position.
    dataXMean = mean(data(:,1));
    dataYMean = mean(data(:,2));
    
    % A plot
    if 0% strcmp(Level{currentfile+2} ,'Level1A') | strcmp(Level{currentfile+2}, 'Level1B') % Turn this on to get a plot for each
      figure(201);
      subplot(4,4,plotnum);
      plotnum= plotnum + 1;
      title(sprintf('ID:%s\nTargetEmotion:%s,  FirstFace %s, AccuracyFirst %d',filename, emo , firstemo, AccuracyFirst))
      hold on;
      
      % Plot the positions of each rectangle 
      for i = 1:6
      x = [emoPosX(1,i) emoPosY(1,i); ...
           emoPosX(1,i) emoPosY(2,i); ...
           emoPosX(2,i) emoPosY(2,i); ...
           emoPosX(2,i) emoPosY(1,i)]; 
        patch(x(:,1),x(:,2),'r');
       
      end
      
      % Plot the first face point. 
      if isfinite(tAll)
        tAll
      plot(data(ceil(tAll * fs),1),data(ceil(tAll * fs),2),'o');
      text(data(ceil(tAll * fs),1),data(ceil(tAll * fs),2),[firstemo ' ' num2str(tAll)]);
      end
      set(gca,'YDir','reverse');
      plot(data(1:end-lastreal-1,1),data(1:end-lastreal-1,2));
      axis([0 1 0 1]);
      figfn = strrep(resFiles(file).name,'.aiff','');
%       pause;
      %saveas(gcf,sprintf('%s-%02d-%s-%s.eps',id{1},fn{8},emo,Locus{currentfile+2}),'eps');
    end
    
    if strcmp(Excerpts{currentfile+2},'excerpt12');
    time = time-0.418;
    timeMove = timeMove-0.418;
    rtime = rtime-0.418;
    tAll = tAll - 0.418;
    end
    
    
    %% List of Column Names
    %
    % numID is the ID of the participant. 
    
    % Filename is :
    % eg: 2011-00-00@16-11-GENT0508-z3252679-07-Level3-Expressed
    %     Year-Day-Month@Hours-Minutes-School/Course-SIDorName-FileNumberFrom25Files-Junk!!-Junk!!
    %     The last two fields are not useful, and will usually be Level3
    %     and one of the two loci but this is incorrect (BUG).
    %     File Order 02-25:
    %     6 Training
    %     7 Level1A
    %     7 Level1B
    %     3 Level2
    %     1 Level3
    
    
    % Level is Level0, Level1A, Level1B, Level2 or Level3
    
    % TimeToPutative: Time taken to get to the putative face
    
    % TimeOutOfBox: Time out of the centre box.
    
    % TimeFirstFace: Time to any of the faces
    
    % TimeForMovement: As discussed above is a threshold for cumulative
    % movement (see readTimeUntilMovement above)
    
    % Locus
    
    % AccuracyProp - See below regarding measure. AccuracyProp compares 
    %                highest proportional time face choice of all faces
    %                to putative face. This is often a smaller number (more
    %                accurate) than the below AccuracyFirst).
    %                In other words, this number is the face numbers that
    %                was rested on for the longest time of any face.  (presumably) NAN
    %                if no face was selected for the entire excerpt.
    
    % AccuracyFirst - Compare first face choice to putative face around the 
    %                 circle of faces. Similar to a GAEL measure. If Happy 
    %                 is Putative and Excited is Chosen FIRST then the
    %                 number will be 1. If Angry is Putative and Excited is
    %                 chosen then number will be 5. 5's and 4's can be
    %                 changed to 1's and 2's respectively if information
    %                 about direction of change is irrelevant to question.
    
    %   
    % 
    % Like - Preference Rating - there were four choices in an order. They
    %        were No, NotSure, Maybe and Yes. They were recorded by
    %        pressing the keys a, s, d, or f respectively
    %        Pressing t allowed the participant to record a comment
    %        In this version of the data processing we haven't included the comments. 
    
    % Know- Familiarity Rating- there were four choices in an order. They
    %        were No, NotSure, HeardItSomewhere and Yes. They were recorded by
    %        pressing the keys q, w, e, or r respectively 
    %        Pressing g allowed the participant to record where they had
    %        heard the excerpt (especially useful with young kids). 
    %        In this version of the data processing we haven't included the comments. 
    
    
    % Emo: Putative Emotion
    
    % Excerpt: excerpt number from 0 - 18, 0 is the control Excited1. Need to look
    %          file name in MAX/MSP patch. And they are reported here, as
    %          follows:
    %     'Excited1_ToyStory.mp3' = excerpt0
    %     'Angry1_UpAUD.mp3'      = excerpt1
    %     'Angry4_ToyStory3.mp3'  = excerpt2
    %     'Angry5_ToyStory3.mp3'  = excerpt3
    %     'Calm1_Nemo.mp3'        = excerpt4
    %     'Calm2_Nemo.mp3'        = excerpt5
    %     'Calm3_Nemo.mp3'        = excerpt6
    %     'Excited4_Cars.mp3'     = excerpt7
    %     'Excited5_Cars.mp3'     = excerpt8
    %     'Excited3_Up.mp3'       = excerpt9
    %     'Happy1_CarsAUD.mp3'    = excerpt10
    %     'Happy2_Monsters.mp3'   = excerpt11
    %     'Happy3_Up.mp3'         = excerpt12
    %     'Sad1_Cars.mp3'         = excerpt13
    %     'Sad6_ToyStory3.mp3'    = excerpt14
    %     'Sad7_ToyStory3.mp3'    = excerpt15
    %     'Scared1_Up.mp3'        = excerpt16
    %     'Scared2_Up.mp3'        = excerpt17
    %     'Scared4_Up.mp3'        = excerpt18
    
    % Age - in years (decimal), if month appears, SO 10 years and 6 months reported as 10.5.
    %       For 2011 data, month was omitted and is therefore rounded down. 
    
    % Age Group - A categorical version of above value, PLEASE SEE 'code for preparing AgeGroup column' BELOW. 
    
    % Mus  - Same as 'Age', but responding to question regarding years of musical training.        
    
    % Gender - Male, Female
    
    % Favourite Face   - 0 to 5 referring to 'Questions.maxpat' Max Patch. 
    % 0 is Scared, 1 is Angry, 2 is Happy, 3 is Sad, 4 is Calm and 5 is Excited.
    
    % Worst Face, same as above. 
    
    % FaceChosenProp - The name of the face chosen for the greatest proportion
    %                  of the time spent as a ratio of on-any-face time. 
    
    % FaceChosenFirst - The name of the face entered first. Can be for only 
    %                   milliseconds as participant flicks to their chosen face.
                       
    
    % ValenceMean Not too bad, but not very useful. Useful for extra
    %             checking info for what the participant has been doing. This is the
    %             Mean x position of the pointer over the recorded continuous response
    %              0.5 is centre point, and greater is positive valence. 
    % ArousalMean As above, greater than 0.5 is negative valence.  
    
    
    % Preceding - describes the preceding excerpt. Usually gives `None' if 
    % Level0 or Level1 or Lfirst of Level2 or Level3. Names preceding excerpt 
    % if Level 2 or Level 3 and the excerpt is preceded by another excerpt.

    % Angry - Proportion OF FACES
    % Scared - Proportion OF FACES
    % Sad - Proportion OF FACES
    % Excited - Proportion OF FACES
    % Happy - Proportion OF FACES
    % Calm - Proportion OF FACES
    
    %%%%% Bug
    %        Where the proportion of faces is NaN for all face columns (Angry, Scared,
    %        Sad, Excited, Happy, Calm) this means that the respondent has
    %        not moved to a face. Check centre and elsewhere to see what they may have done,
    %        However, if FaceChosenProp or FaceChosenFirst is Angry, this
    %        is incorrect (a bug). Usually this happens for Level2, but does happen
    %        for Level3 and Level1 sometimes. Exclude if Possible. 
    
    
    % Centre - Proportion OF TOTAL TIME
    % Elsewhere - Proportion OF TOTAL TIME
    outResponseTime(num) = time;
    outMoveTime(num) = timeMove;
    outAnyTime(num) = rtime;
    outFirstFace(num) = tAll;
    
    outLocus(num) = Locus(currentfile+2);
    outLike(num) = Like(currentfile+2);
    outKnow(num) = Know(currentfile+2);
    outLevel(num) =  Level(currentfile+2);
    outFilename(num) = {filename};    % PLEASE NOTE the last two fields '-' of the 'filename' column will always
    % say something like 'Level3-Felt', but this is usually not used, and is
    % not correct. The Level and Locus columns are correct for getting this information. 
    outAccuracy(num) = Accuracy;
    outAccuracyFirst(num) = AccuracyFirst;
    outEmo{num} = emo;
    outExcerpt{num} = Excerpts{currentfile+2};
    outID{num} = id;
    outAge(num) = age;
    outLanguage{num} = lower(lang);
    outSID{num}     =  SID;
    outTopfaceProp{num} = topface;
    outTopfaceFirst{num} = firstemo;
    outTargetChosen{num} = targetemochosen;
    outXMean(num) = dataXMean;
    outYMean(num) = dataYMean;
    outPreceding{num}  = Preceding{currentfile+2};
    outAngry(num) = prop(1);
    outScared(num) = prop(2);
    outSad(num) = prop(3);
    outCalm(num) = prop(4);
    outHappy(num) = prop(5);
    outExcited(num) = prop(6);
    outCentre(num) = prop(7);
    outElsewhere(num) = prop(8);
    % This is code for preparing AgeGroup column. 
    if age>16
      outAgeGroup{num} = 'Tertiary';
    elseif age>10
      outAgeGroup{num} = '5th Grade';
    elseif age>7
      outAgeGroup{num} = '2nd Grade';
    elseif age>3
      outAgeGroup{num} = 'Kindergarten';
   elseif age<=3
      outAgeGroup{num} = 'Tertiary';
    
    end
    
    outMus(num) = mus;
    outGender{num} = gender{1};
    outFaveFace(num) = faveFace;
    outWorstFace(num) = worstFace;
    
    % Write out the results

    
    
    
    %% jumping in here for timeseries. 
    % Everything has been calculated so we can calculate timeseries. 
    
    if isempty(strfind(Excerpts{currentfile+2},'Training0'))
        excNum = str2num(strrep(Excerpts{currentfile+2},'excerpt',''));
        excNum = excNum + 1;
        fHandle = fHandles(excNum);
        
        if strfind(Excerpts{currentfile+2},'Training')
            excNum = str2num(strrep(Excerpts{currentfile+2},'Training',''));
            fHandle = fHandlesTraining(excNum);
        end
        assessAndWriteTimeseries(fs, fHandle, data, id{1}, SID, Locus(currentfile+2), Like(currentfile+2), Know(currentfile+2) ,Level(currentfile+2), filename, Accuracy, AccuracyFirst, Excerpts{currentfile+2}, age, lang, gender{1}, mus,outPreceding{num})
    end
    
    
    %% NOTES and Comments 5/1/12
    % PLEASE NOTE the last two fields '-' of the 'filename' column will always
    % say something like 'Level3-Felt', but this is usually not used, and is
    % not correct. The Level and Locus columns are correct for getting this information. 
    
    % For Level 2 data, for the March 2011 tranche, 2/3 of the responses
    % will be NaN as there was an error with the recording of the data. If
    % you look at the 4-channel audio files you will see they are blank for
    % these participant responses. These will have a filename starting with
    % 2011-00-00, or the 2 cases 2011-10-03 or 2011-09-03 for z3220996 and z33368083
    % respectively.
    
    
    
    
    fprintf(fidout,'%s\t%s\t%s\t%f\t%f\t%f\t%f\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%f\t%s\t%f\t%s\t%s\t%s\t%d\t%d\t%s\t%s\t%d\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n',...
      outID{num}{1},outFilename{num},outLevel{num},...
      outResponseTime(num),outMoveTime(num),outAnyTime(num),outFirstFace(num),...
      outLocus{num},num2str(outAccuracy(num)),num2str(outAccuracyFirst(num)), outLike{num},outKnow{num},outEmo{num},outPreceding{num},outExcerpt{num},...
      outAge(num),outAgeGroup{num},outMus(num),...
      outGender{num},outLanguage{num},outSID{num},outFaveFace(num), outWorstFace(num),...
      outTopfaceProp{num},outTopfaceFirst{num},outTargetChosen{num},...
      outXMean(num),outYMean(num),...
      outAngry(num), outScared(num), outSad(num), outCalm(num), outHappy(num), outExcited(num), outCentre(num),outElsewhere(num));
    num = num + 1;
  end
  %%%%% End loop for demographic files
end
%%%
for fh = 1:19
    fclose(fHandles(fh));
end
fclose(fidout);


